//
//  UITextField+TextFieldYMJ.m
//  拉勾7.17
//
//  Created by dllo on 16/7/17.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "UITextField+TextFieldYMJ.h"

@implementation UITextField (TextFieldYMJ)
+ (InheritCustomIdentifyPhoneNumberTextField *)createPasswordTextFieldOnLoadPageWithRightView {
    InheritCustomIdentifyPhoneNumberTextField *text = [[InheritCustomIdentifyPhoneNumberTextField alloc] initWithFrame:CGRectMake(0, 0, WIDTH - 40, 53)];
    text.center = CGPointMake(WIDTH / 2, HEIGHT / 2 + 53 + 1.5);
    // 黑色透明度0.2
    text.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
    text.placeholder = @"请输入密码";
    text.clearButtonMode = UITextFieldViewModeWhileEditing;
    
    // 左视图是view上面铺一层passwordImageVIew
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
    // 黑色透明度0.2
    view.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.2];
    text.phoneImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 12, 30, 30)];
    
    [text.phoneImageView setImage:[UIImage imageNamed:@"icon_password"]];
    [view addSubview:text.phoneImageView];
    text.leftView = view;
    // 设置左视图开启
    text.leftViewMode = UITextFieldViewModeAlways;
    // 键盘模式
    text.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    // 设置密码模式
    text.secureTextEntry = YES;
    text.clearsOnBeginEditing = YES;
    // 添加右视图
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 20)];
    rightView.backgroundColor = [UIColor clearColor];
    // 添加竖线
    UIView *verticalline = [[UIView alloc] initWithFrame:CGRectMake(0, 53/ 4, 3, 53 / 2)];
    verticalline.backgroundColor = [UIColor darkGrayColor];
    

    // 右视图添加button
    text.getIdentifyIconButton = [UIButton buttonWithType:UIButtonTypeCustom];
    text.getIdentifyIconButton.frame = CGRectMake(0, 53 / 4 + 2, 150, 20);
    text.getIdentifyIconButton.backgroundColor = [UIColor clearColor];
    [text.getIdentifyIconButton setTitle:@"获取验证码" forState:0];
    [text.getIdentifyIconButton setTitleColor:COLOR1 forState:0];
    text.getIdentifyIconButton.titleLabel.font = [UIFont italicSystemFontOfSize:20];
    // 修改button 的字体位置第一种方法无效
    //    text.getIdentifyIconButton.titleLabel.textAlignment = 2;
    text.getIdentifyIconButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    // 此时文字会紧贴边框,将文字右边移动几个像素距离即可
    text.getIdentifyIconButton.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    [rightView addSubview:text.getIdentifyIconButton];
    [rightView addSubview:verticalline];
    text.rightView = rightView;
    text.rightViewMode = UITextFieldViewModeAlways;
#pragma mark - 一首 左视图或右视图当重写它的坐标大小时直接放进去的视图会变成设置的那样,
    return text;
}
+ (CustomIdentifyPhoneNumberTextField *)createIdentifyIconTextField {
    CustomIdentifyPhoneNumberTextField *text = [[CustomIdentifyPhoneNumberTextField alloc] initWithFrame:CGRectMake(0, 0, WIDTH - 40, 53)];
    text.center = CGPointMake(WIDTH / 2, 150 + 53 );
    text.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
    view.backgroundColor = [UIColor clearColor];
    text.placeholder = @"验证码";
    text.phoneImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_identifyIcon@%&$3x"]];
    
    text.phoneImageView.frame = CGRectMake(0, 12.5, 25, 25);
    // 左边视图如果直接赋一个imageView(不给大小长度)他会自动适应textfield的高度.
    [view addSubview:text.phoneImageView];
    text.leftView = view;
    text.leftViewMode = UITextFieldViewModeAlways;
    text.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    // 添加右视图
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 50)];
    rightView.backgroundColor = [UIColor clearColor];
    // 右视图添加button
    text.getIdentifyIconButton = [UIButton buttonWithType:UIButtonTypeCustom];
    text.getIdentifyIconButton.frame = rightView.frame;
    text.getIdentifyIconButton.backgroundColor = [UIColor clearColor];
    [text.getIdentifyIconButton setTitle:@"获取验证码" forState:0];
    [text.getIdentifyIconButton setTitleColor:COLOR1 forState:0];
    text.getIdentifyIconButton.titleLabel.font = [UIFont italicSystemFontOfSize:20];
    // 修改button 的字体位置第一种方法无效
//    text.getIdentifyIconButton.titleLabel.textAlignment = 2;
    text.getIdentifyIconButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    // 此时文字会紧贴边框,将文字右边移动几个像素距离即可
    text.getIdentifyIconButton.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    [rightView addSubview:text.getIdentifyIconButton];
    text.rightView = rightView;
    text.rightViewMode = UITextFieldViewModeAlways;
    return text;
}
+ (CustomIdentifyPhoneNumberTextField *)createPhoneNumbertextField {
    CustomIdentifyPhoneNumberTextField *text = [[CustomIdentifyPhoneNumberTextField alloc] initWithFrame:CGRectMake(0, 0, WIDTH - 40, 53)];
    text.center = CGPointMake(WIDTH / 2, 150);
    text.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
    view.backgroundColor = [UIColor clearColor];
    text.placeholder = @"手机号(仅支持中国大陆手机)";
    text.phoneImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_iphone2"]];
    
    text.phoneImageView.frame = CGRectMake(0, 12.5, 25, 25);
    // 左边视图如果直接赋一个imageView(不给大小长度)他会自动适应textfield的高度.
    [view addSubview:text.phoneImageView];
    text.leftView = view;
    text.leftViewMode = UITextFieldViewModeAlways;
    text.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    return text;
    
}
+ (CustomTextField *)createPasswordTextFieldOnLoadPage {
    CustomTextField *text = [[CustomTextField alloc] initWithFrame:CGRectMake(0, 0, WIDTH - 40, 53)];
    text.center = CGPointMake(WIDTH / 2, HEIGHT / 2 + 53 + 1.5);
    // 黑色透明度0.2
    text.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
    text.placeholder = @"请输入密码";
    text.clearButtonMode = UITextFieldViewModeWhileEditing;
   
    // 左视图是view上面铺一层passwordImageVIew
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
    // 黑色透明度0.2
    view.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.2];
    text.personImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 12, 30, 30)];
    
    [text.personImageView setImage:[UIImage imageNamed:@"icon_password"]];
    [view addSubview:text.personImageView];
    text.leftView = view;
    // 设置左视图开启
    text.leftViewMode = UITextFieldViewModeAlways;
    // 键盘模式
    text.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    // 设置密码模式
    text.secureTextEntry = YES;
    text.clearsOnBeginEditing = YES;
    return text;
}
+ (CustomTextField *)createPersonTextFieldOnLoadPage {
    CustomTextField *text = [[CustomTextField alloc] initWithFrame:CGRectMake(0, 0, WIDTH - 40, 53)];
    text.center = CGPointMake(WIDTH / 2, HEIGHT / 2);
    text.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.2];
    text.placeholder = @"请输入已验证的手机号或邮箱";
    text.clearButtonMode = UITextFieldViewModeWhileEditing;
    
    // 左视图是view上面铺一层personImageVIew
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
    view.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.2];
    text.personImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 12, 30, 30)];
    
    [text.personImageView setImage:[UIImage imageNamed:@"icon_person"]];
    [view addSubview:text.personImageView];
    text.leftView = view;
    // 设置左视图开启
    text.leftViewMode = UITextFieldViewModeAlways;
   
    return text;
}
@end
